package com.mhg.reflect;

import com.mhg.collection.bean.Person;

import java.lang.reflect.Method;


//Method方法对象
public class Demo_04 {

	public static void main(String[] args) throws Exception{
		//1.反射的入口
		Class<?> clazz = Class.forName("com.demo1.reflect.Person");
		//2.创建对象
		Person p = (Person)clazz.newInstance();
		
		//3.调用
		//1.被public 修饰的方法
		Method m = clazz.getMethod("eat");
		m.invoke(p);
		//有参方法
		Method m2 = clazz.getMethod("eat", int.class);
		m2.invoke(p, 10);
		
		//2.所有的
		Method m3 = clazz.getDeclaredMethod("sum", int.class,int.class);
		m3.setAccessible(true);
		Integer i = (Integer)m3.invoke(p, 2,1);
		System.out.println(i);
	}

}